import { reqCategoryList, reqGetBannerList, reqFloorList } from "@/api";

const state = {
  msg: "这里是home的store",
  CategoryList: [],
  bannerList: [],
  floorList: [],
};

const mutations = {
  // 修改三级联动菜单
  changeCategoryList(state, CategoryList) {
    state.CategoryList = CategoryList;
  },

  // 修改首页轮播bannerList
  changeBannerList(state, bannerList) {
    state.bannerList = bannerList;
  },

  // 修改首页轮播floorList
  changeFloorList(state, floorList) {
    state.floorList = floorList;
  },
};

const actions = {
  // 调用api，存储三级联动的数据
  async categoryList({ commit }) {
    let result = await reqCategoryList();
    if (result.code === 200) {
      commit("changeCategoryList", result.data);
    }
  },

  // 获取首页轮播图的数据
  async getBannerList({ commit }) {
    let res = await reqGetBannerList();
    // console.log(res)
    if (res.code === 200) {
      commit("changeBannerList", res.data);
    }
  },

  // 获取首页轮播图的floor数据
  async getFloorList({ commit }) {
    let res = await reqFloorList();
    if (res.code === 200) {
      commit("changeFloorList", res.data);
    }
  },
};

const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
